import { observable, action, autorun, toJS } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx'
const { TableStore } = WeaTableNew;
import { ExchangeStore } from "../../exchangeStore"
import { ProjectInfoStore } from '../../projectInfoStore';
import { AddProjectStore } from "../../addProjectStore";
import { ShareStore } from '../../shareStore';
import { message } from 'antd';
import * as  Apis from '../../../apis/project';
import { WeaLocaleProvider } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
export class ProjectSubStore {
	@observable prjid = "";
    @observable showSearchAd = false  // 高级搜索显示
    @observable rightMenu = [];
    @observable prjSubStore = new TableStore();  //子项目
	@observable prjSubform = new WeaForm();
	@observable prjsubRight = {
		hasRight: false,
		verified: false
	}
	@observable addProjectStore = new AddProjectStore();
    @observable exchangeStore = new ExchangeStore();
    @observable projectInfoStore = new ProjectInfoStore();
	@observable shareTableStore = new TableStore(); //共享
	@observable shareStore = new ShareStore();
	@observable isShowShare = false;
	@observable shareRight = {
		hasRight: false,
		verified: false
	}
    //高级搜索显隐
	setShowSearchAd = (bool) => {
		this.showSearchAd = bool
	}
    @action
	reLoad = (tableStore) => {
		tableStore.getDatas(tableStore.dataKey, tableStore.current, tableStore.pageSize, tableStore.sortParams)
	}

	initData = (prjid) => {
		this.prjid = prjid;
		this.getPrjSubList();
		this.getPrjSubCondition();
	}

    //子项目列表
	getPrjSubList = (params = {}) => {
        this.loading = true;
		const searchParamsAd = this.prjSubform.getFormParams();
		const newParams = { prjid: this.prjid, ...searchParamsAd, ...params };
		Apis.getPrjSubList(newParams).then(data => {
			if (!data.isright && typeof (data.isright) !== "undefined") {
				this.prjsubRight = {
					hasRight: data.isright,
					verified: true
				};
			} else {
				this.prjsubRight = {
					hasRight: true,
					verified: true
				};
				this.prjSubStore.getDatas(data.sessionkey, 1);
				this.rightMenu = data.rightMenus;
				this.loading = false;
			}
		});
    }

    appendFormFields = (value) => {
		this.setFormFields(value);
    }
    
    //高级搜索设值
	setFormFields = (value) => {
	    //子项目
        this.prjSubform.updateFields(value, false);    //true代表完全覆盖方式更新条件值
    }
    
    clearFormFields = () => {
        this.prjSubform.reset();      //清除查询条件值
	}

	//子项目  高级搜索
	getPrjSubCondition = () => {
		this.prjSubform = new WeaForm();
		Apis.getPrjCondition({ conditiontype: "prjsub" }).then(data => {
			this.condition = data.condition;

			this.prjSubform && !this.prjSubform.isFormInit && this.prjSubform.initFormFields(data.condition);
		})
	}

	
	//子项目执行操作
	@action
	doSubPlanOpt = (params = {}) => {
		Apis.doPlanOpt(params).then(data => {
			message.success(data.msg);
			this.getPrjSubList();
		});
	}

	onShowColumn = () => {   //显示定制列
		this.prjSubStore.setColSetVisible(true);
		this.prjSubStore.tableColSet(true)
	}

}

